<template>
    <div class="main">
      <input type="tel" placeholder="请输入手机号" v-model="phone">
      <a @click="bind()">绑定</a>
    </div>
</template>

<script>
  import {
    baseUrl,
    myUrl,
    auth,
  } from "@/assets/public";
    export default {
        name: 'main',
        data() {
            return {
              openid:"",
              phone:"",
            }
        },
        mounted() {
          var now_url = window.location.href;
          var url_param = window.location.search;
          if(url_param.indexOf('openid') > 0){
            var params = url_param.substr(1).split('&');
            for(var i=0;i < params.length;i++){
              var temp = params[i].split("=");
              if(temp[0] == 'openid'){
                localStorage.openid = temp[1];
              }
            }
          }
            else{
              var basic_url = 'http://bfwechat.beautyfarm.com.cn/Url.aspx?scope=snsapi_base&url=';
              location.href = basic_url+encodeURIComponent(now_url);
            }

        },
        methods: {
          bind:function () {
            var that =this;
            that.openid = localStorage.openid;
            $.ajax({
              type:"POST",
              url:baseUrl+"/api/dobing",
              dataType:"json",
              data:{
                "phone":that.phone,
                "openid":that.openid,
              },
              success:function (res) {
                console.log(res);
                if(res.status == 1){
                  that.$router.push("/");
                }else {
                  alert(res.message);
                }
              }
            })
          }
        }
    }
</script>

<style scoped>
    .main {
      width: 100%;
      height: 100vh;
      text-align: center;
    }
    .main input {
      width: 80%;
      height:1rem;
      line-height:1rem;
      color: #666;
      outline:none;
      font-size:.6rem;
      margin-top:3rem;
      border:1px solid #333;
    }
    .main a {
      display: block;
      width: 60%;
      height:1.5rem;
      margin:0 auto;
      background: #333;
      color: #ffffff;
      font-size:.4rem;
      letter-spacing: 20px;
      position: relative;
      margin-top:1rem;
      text-align: center;
      line-height:1.5rem;
    }
</style>
